<?

session_start();

require("Misc.php");
require("helpers/Oracle.php");
require("helpers/UID.php");
require("controllers/GlobalProcessors.php");
require("models/GlobalFetchers.php");
require("models/GlobalHandlers.php");

$GProcessors = new GlobalProcessors;
$GFetchers   = new GlobalFetchers;
$Misc        = new Misc;

/**
* Reset all session vars
*
*/
if(isset($_SESSION) && sizeof($_SESSION) != 0 && !$_POST["continue"]){

		unset($_SESSION);
		session_destroy();
		$Misc->jumpTo(0,"index.php");
}

?>

<link rel="stylesheet" type="text/css" href="myMenu.css">

<?

if($_POST["continue"]){

	/**
	* Global date defined
	* why i used -1, so i could have a day back
	* since we are working with
	* the previous date of transactions
	*
	*/
	$_SESSION["GDate"]	= date("d-m-Y",
	                           mktime(0,0,0, date("m"), date("d") - 1, date("Y")));

	$_SESSION["company"] 		= "ECS";
	$_SESSION["user"]				= $_POST["user"];
	$_SESSION["pass"]				= $_POST["pass"];
	$_SESSION["ORCL"] 			= "necs_appl";
	$_SESSION["ORCLU"]			= "necs_general";
	$_SESSION["ORCLS"]			= "necs_appl";
	$_SESSION["ORCLBO"]     = "necs_backup";
	//$_SESSION["SID"]				=	"192.168.4.60/ecs";
	$_SESSION["SID"]       = "localhost/xe";
	$_SESSION["OPASS"]			= "ecsprj";

	$srcDbHdrUser    = "USERID_HDR";
	$srcDbDtlUser    = "USERID_DTL";
	$srcDbGrlSetting = "GRL_SETTING";

	$Db = new Oracle;

  $Db->init($_SESSION["ORCLU"],
            $_SESSION["OPASS"],
            $_SESSION["SID"],
            _NO_COMMENT);

  if($Db->connect()){

    /**
  	* Additional variables init
  	*
  	*/
  	$GProcessors->procVarsAdditional();

    /**
  	* check the login information
  	*
  	*/
  	if($GFetchers->fetchLogin($Db,
              	              $_POST["user"],
              	              $_POST["pass"],
              	              $_SESSION["company"],
              	              $srcDbHdrUser)){

      $Db->dc();

      /**
      * Init the user infos
      *
      */
      $UID =  new UIDMth( $_SESSION["user"],
                          $_SESSION["company"],
                          $_SESSION["ORCLU"],
                          $_SESSION["OPASS"],
                          $_SESSION["SID"]);

      $_SESSION["serUID"] = serialize($UID);

      /**
       * init the general setting
       */
      $Db->init($_SESSION["ORCL"],
                $_SESSION["OPASS"],
                $_SESSION["SID"],
                _NO_COMMENT);

      if($Db->connect()){

        $GFetchers->fetchGrlSettingAll($Db,
                                       $srcDbGrlSetting,
                                       $grlSetting);

        $_SESSION["baseCurrency"] = $grlSetting["CURRENCY"][0];
        $_SESSION["baseMethod"]   = $grlSetting["METHOD"][0];
        $_SESSION["baseLevelD"]   = $grlSetting["LEVELD"][0];

        $Db->dc();
      }else{

        $Misc->usrDieJs(_DB_CONN_ERROR);
      }

  	  $Misc->jumpTo(2, "index.php3");
  	}else{

  	  $_POST["flsMessage"] = "Invalid Login";

  	  $GProcessors->procLogin($_POST["flsMessage"]);
  	}

  }else{

    $Misc->usrDieJs("Oracle connection failed");
  }

}else{

	$GProcessors->procLogin($_POST["flsMessage"]);
}
?>